package SwordFingerOffer;

public class Q21_ExchangeArray {
    //调整数组 奇数在前 偶数在后
    //双指针
    public int[] exchange(int[] nums) {

        int left = 0;
        int right = nums.length - 1;

        while (left < right){
            //如果是偶数
            if (nums[left] % 2 == 0){
                swap(nums, left, right--);
            }else {
                //如果是奇数
                left ++;
            }
        }
        return nums;
    }
    //数组内交换元素
    public static void swap(int[] arr, int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
